/*
 * 
 * v1.2 by tonydon
 */
package cn.txdnet.txweb.mail;

import txdnet.util.mail.SmtpMailer;

/**
 *
 * @author txdnet
 */
public class SimpleSender extends Sender {

    private String tomail;
    private String senderName;
    private String subject;
    private String content;
    private boolean isHtml;

    public SimpleSender() {
    }

    public SimpleSender(String tomail, String senderName, String subject, String content, boolean isHtml) {
        this.tomail = tomail;
        this.senderName = senderName;
        this.subject = subject;
        this.content = content;
        this.isHtml = isHtml;
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * @param content the content to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public Result dispatchMessages() {
        boolean flag = true;
        if (isHtml) {
            flag = SmtpMailer.sendHtmlMail(
                    getTomail(),
                    getSenderName(),
                    getSubject(),
                    getContent(),
                    EmailConfig.getRandomSmtpParam());
        } else {
            flag = SmtpMailer.sendTextMail(
                    getTomail(),
                    getSenderName(),
                    getSubject(),
                    getContent(),
                    EmailConfig.getRandomSmtpParam());
        }
        Result r = new Result();
        r.setSendFlag(flag);
        r.setMail(tomail);
        return r;
    }

    /**
     * @return the tomail
     */
    public String getTomail() {
        return tomail;
    }

    /**
     * @param tomail the tomail to set
     */
    public void setTomail(String tomail) {
        this.tomail = tomail;
    }

    /**
     * @return the senderName
     */
    public String getSenderName() {
        return senderName;
    }

    /**
     * @param senderName the senderName to set
     */
    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the isHtml
     */
    public boolean getIsHtml() {
        return isHtml;
    }

    /**
     * @param isHtml the isHtml to set
     */
    public void setIsHtml(boolean isHtml) {
        this.isHtml = isHtml;
    }
}
